package
{
	import starling.display.MovieClip;
	import com.util.Camera;
	import starling.events.Event;

	public class WorldObject extends GameObject
	{	
		private var anim:MovieClip;
		private var _world:World;
		
		public function WorldObject(data:Object, texID:uint = -1)
		{
			super();
			_world = data as World;
			if(texID >= 0)
			{				
				anim = new MovieClip(Assets.getLevelMapAtlas().getTextures(_world.getTMXTileMap().tileMapper[texID]),10);
				addChild(anim);
				this.addEventListener(starling.events.Event.ADDED_TO_STAGE, onAddedToStage);
			}			
		}
		
		private function onAddedToStage(event:Event):void
		{
			this.removeEventListener(starling.events.Event.ADDED_TO_STAGE, null);
			
			init();
		}
		
		public function init():void
		{
			World.juggler.add(this.anim);			
		}
		
		public override function onEnterFrame(dt:Number):void
		{
		}		
				
		public function intersectsLine(x1:Number, x2:Number):Boolean
		{
			var objX1:Number = x;
			var objX2:Number = objX1 + this.width - 1;
			return (objX1 > x1 || objX2 > x1);	/**Collision test for objects to the right are turned off for now because 4 columns 
			* to the right of camera that are not in view are cached in advance for continuity
			**/ //&& (objX1 < x2 || objX2 < x2); 
		}
		
		public override function dispose():void 
		{			
			super.dispose();
			World.juggler.remove(this.anim);
			anim = null;						 						
		}
	}
}